import { prop, modelOptions, Ref, arrayProp } from '@typegoose/typegoose'
import { ApiProperty } from '@nestjs/swagger'
import { Episode } from './episode.model'



@modelOptions({
    schemaOptions: {
        timestamps: true,
        toJSON: {
            virtuals: true
        }
    }
})
export class Course {
    @ApiProperty({
        description: '课程名称'
    })
    @prop()
    name: string

    @ApiProperty({
        description: '课程封面'
    })
    @prop()
    cover: string

    @arrayProp({
        ref: 'Episode',  // 参考的是 Episode
        localField: '_id', // 外键用Course  _id 关联  Episode里面的 course
        foreignField: 'course' // 
    })
    episodes: Ref<Episode>[]
    // 参考 Course 的数组
}